#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T;
int d,v,a;
int l1[N],r1[N];
int p[N];
int l2[N],r2[N];
int ans;
struct car
{
    int l=0,r=0;
}c[N];
bool cmp(car x,car y)
{
    if(x.r==y.r)
        return x.l<y.l;
    return x.r>y.r;
}
int main()
{
    std::ios::sync_with_stdio(false);
   freopen("detect.in","r",stdin);
   freopen("detect.out","w",stdout);
   cin>>T;
    while(T--)
    {
        int n,m,L,V;
        ans=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>d>>v>>a;
            l1[i]=r1[i]=-1;
            if(a==0)
                if(v>V)
                    l1[i]=d,r1[i]=L;
            if(a>0)
            {
                if(v>V)
                    l1[i]=d,r1[i]=L;
                else
                {
                    l1[i]=(V*V-v*v)/2/a+d+1;
                    r1[i]=L;
                    if(l1[i]>r1[i])
                        l1[i]=r1[i]=-1;

                }
            }
            if(a<0)
            {
                if(v>V)
                {
                    l1[i]=d;
                    r1[i]=ceil((V*V-v*v)*1.0/2/a+d-1);
                    if(l1[i]>r1[i])
                        l1[i]=r1[i]=-1;
                }
            }
        }
        for(int i=1;i<=m;i++)
            cin>>p[i];
        for(int i=1;i<=n;i++)
        {
            if(l1[i]==-1&&r1[i]==-1)
                continue;
            ans++;
            int l=1,r=m,mid;
            while(l<r)
            {
                mid=(l+r)/2;
                if(p[mid]>=l1[i])
                    r=mid;
                else
                    l=mid+1;
            }
            c[i].l=r;
            l=1,r=m;
            while(l<r)
            {
                mid=(l+r+1)/2;
                if(p[mid]<=r1[i])
                    l=mid;
                else
                    r=mid-1;
            }
            c[i].r=l;
            if(c[i].l>c[i].r||p[c[i].l]<l1[i]||p[c[i].r]>r1[i])
                c[i].l=c[i].r=0,ans--;
        }
        sort(c+1,c+n+1,cmp);
        int res1=0,l=m+10,r=m+10;
        for(int i=1;i<=n;i++)
        {
            if(c[i].l==0&&c[i].r==0)
                break;
            if(c[i].r>=l)
            {
                r=min(c[i].r,r);
                l=max(l,c[i].l);
            }
            else
            {
                res1++;
                l=c[i].l;
                r=c[i].r;
            }
            c[i].l=0,c[i].r=0;
        }
        cout<<ans<<' '<<m-res1<<endl;
    }
    return 0;
}

